package xiancheng;

public class threadtest2 {
    public static void main(String[] args) {
        MyRunable target=new MyRunable();

       Thread t1=new Thread(target,"线程1");
       Thread t2=new Thread(target,"线程2");
       Thread t3=new Thread(target,"线程3");
       Thread t4=new Thread(target,"线程4");

       t1.start();
       t2.start();
       t3.start();
       t4.start();
    }


    static class MyRunable implements Runnable {
//创建成员变量，用来保存票数。静态变量
        static int tickets=100;

        @Override
        public void run() {

            while (true){
                try {
                    Thread.sleep(10);

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+"="+tickets--);
                if (tickets <=0) {
                    break;
                }

            }

        }
    }
}
